# coding=utf-8

import sys
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

# 声明 queue，并指定持久化
channel.queue_declare(queue='task_queue', durable=True)

# 从命令行读取参数作为消息
message = ' '.join(sys.argv[1:]) or "Hello World!"

# 发布消息，并指定将消息持久存储
channel.basic_publish(exchange='',
                      routing_key='task_queue',
                      body=message,
                      properties=pika.BasicProperties(
                         delivery_mode=2, # 让消息被持久存储
                      ))

print " [x] Sent %r" % (message,)

